package com.rightsidetech.http.controller.admin.trade;

import com.github.pagehelper.PageInfo;
import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.commom.enums.CodeIdEnum;
import com.rightsidetech.http.aspect.Auth;
import com.rightsidetech.http.aspect.Log;
import com.rightsidetech.http.aspect.Token;
import com.rightsidetech.http.base.BaseController;
import com.rightsidetech.system.entity.SysUserLoginInfo;
import com.rightsidetech.system.service.SysCompanyAreaService;
import com.rightsidetech.system.service.SysUserLoginInfoService;
import com.rightsidetech.trade.dtos.request.integral.IntegralOperateRecordReq;
import com.rightsidetech.trade.dtos.request.integral.LogisticsOrderNoReq;
import com.rightsidetech.trade.dtos.response.integral.IntegralOperateRecordResp;
import com.rightsidetech.trade.service.TdIntegralOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/integral_trade")
@ShenyuSpringMvcClient(path = "/admin/integral_trade/**")
@Api(tags = "admin:积分兑换记录")
public class TdAdminIntegralOrderController extends BaseController {

    @Resource
    private TdIntegralOrderService tdIntegralOrderService;
    @Resource
    private SysUserLoginInfoService sysUserLoginInfoService;
    @Resource
    private SysCompanyAreaService sysCompanyAreaService;

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @GetMapping("/page")
    @ApiOperation("兑换列表")
    public ResponseData<PageInfo<IntegralOperateRecordResp>> page(IntegralOperateRecordReq req){
        SysUserLoginInfo loginInfo = sysUserLoginInfoService.selectByLoginInfo(Long.parseLong(getAttribute()));
        if (ObjectUtils.isEmpty(loginInfo)){
            return ResponseData.fail(CodeIdEnum.NOLOGINACCOUNT);
        }
        if(loginInfo.getSysCompanyAreaId() != 0){
            req.setAreaId(loginInfo.getSysCompanyAreaId());
        }
        return tdIntegralOrderService.operateRecordPage(req);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @PostMapping("/logistics")
    @ApiOperation("快递单号")
    public ResponseData logisticsNo(@RequestBody LogisticsOrderNoReq req){
        return tdIntegralOrderService.logisticsOrderNo(req);
    }
}
